package com.chen.Dome6TCP3;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.*;

public class ServerDome{
    public static void main(String[] args) throws IOException {
        //目标：完成TCP通信的服务端，实现bs架构
        System.out.println("服务端已经启动...");
        //1.创建一个服务器端对象
        ServerSocket ss=new ServerSocket(8080);
        //使用线程池进行开发
        ExecutorService pool=new ThreadPoolExecutor(5, 10, 10,
                TimeUnit.SECONDS, new ArrayBlockingQueue<>(100), new ThreadPoolExecutor.AbortPolicy());

        while (true) {
            Socket s=ss.accept();
            System.out.println("一个客户端建立了连接"+s.getInetAddress().getHostAddress());
           pool.execute(new ServerReader(s));
        }
    }
}
